<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/28
 * Time: 17:33
 */

include "config.php";

if($_SERVER["REQUEST_METHOD"] == "POST"){

    $file = $_FILES["ufile"];
    $filePath = "./upload/" . $file["name"];

    if(isset($_POST["uname"]) && isset($_POST["upwd"]) && isset($_POST["usex"]) && isset($_POST["uemail"])){

        //1.保存路径
        if(move_uploaded_file($file["tmp_name"], $filePath)){
            //就开始执行sql语句
            //2.sql语句
            $inertSQL = "INSERT INTO userinfo (`u_name`,`u_pwd`,`u_sex`,`u_email`,`u_path`)VALUES(?,?,?,?,?) ;";
            //3.预查询
            $stmt = $conn->prepare($inertSQL);
            //4.绑定参数
            $stmt->bind_param("sssss", $_POST["uname"], $_POST["upwd"], $_POST["usex"], $_POST["uemail"], $filePath);
            $stmt->execute();


            if($stmt->affected_rows>=1){
                print_r(json_encode(array("status"=>1,"msg"=>"注册成功")));
            }else{
                print_r(json_encode(array("status"=>0,"msg"=>"注册失败")));
            }
            $stmt->close();

        } else {
            //不保存sql
            print_r(json_encode(array("status"=>-2,"msg"=>"注册失败,图片未保存成功")));
        }


    }

}else{
    print_r(json_encode(array("status"=>-1,"msg"=>"不支持get请求")));
}

$conn->close();